package com.medicine.hbp.adapter;

import java.util.Arrays;
import java.util.List;

import com.medicine.hbp.mob.OptionListVo;
import com.medicine.hbp.mob.artLaberVo;
import com.medicine.hbp.R;
import com.umeng.socialize.utils.Log;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
/**
 * @author Administrator
 *
 */
public class BqianAdapter extends BaseAdapter {
	/**
	 */
	public List<artLaberVo> laberVos;
	private LayoutInflater inflater;
	private Activity activity;
	private String bqid="";
	/**
	 */
	private int type;
	public BqianAdapter(Activity activity, List<artLaberVo> laberVos,String bqid) {
		this.laberVos = laberVos;
		this.activity = activity;
		this.bqid = bqid;
		if(!TextUtils.isEmpty(bqid)){
			List<String> result = Arrays.asList(this.bqid.split(","));  
			for (int i = 0; i < this.laberVos.size(); i++) {
				for (int j = 0; j < result.size(); j++) {
					Log.e("ccccccc",result.get(j));
					if(this.laberVos.get(i).laberId==Integer.valueOf(result.get(j))){
						this.laberVos.get(i).laderBoolean=true;
					}
				}
			}
		}
		inflater = LayoutInflater.from(activity);
	}
	public List<artLaberVo> getLaberVos() {
			return laberVos;
	}
	@Override
	public int getCount() {
		return laberVos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View view, ViewGroup arg2) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.biaoqian_item, null);
			holder.textView = (TextView) view.findViewById(R.id.vote_item_name);
			holder.image_vote = (ImageView) view.findViewById(R.id.image_vote);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		artLaberVo listVo = laberVos.get(arg0);
		if (listVo != null) {
			holder.textView.setText(listVo.laberName);
			view.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					for (int i = 0; i < laberVos.size(); i++) {
						if (i == arg0&&laberVos.get(i).laderBoolean == false) {
							laberVos.get(i).laderBoolean = true;
						} else if(i == arg0&&laberVos.get(i).laderBoolean == true){
							laberVos.get(i).laderBoolean = false;
						}
					}
					notifyDataSetChanged();
				}
			});
			if (listVo.laderBoolean) {
				holder.image_vote.setImageDrawable(activity.getResources().getDrawable(R.mipmap.vote_1));
			} else {
				holder.image_vote.setImageDrawable(activity.getResources().getDrawable(R.mipmap.vote_2));
			}
		}
		return view;
	}

	class ViewHolder {
		TextView textView;
		ImageView image_vote;
	}

}
